package org.vacoor.nothing.web.servlet;

import javax.servlet.*;
import javax.servlet.http.*;

/**
 * For DEBUG
 *
 * @author vacoor
 */
public class FullyListener implements
        ServletContextListener, ServletContextAttributeListener,
        ServletRequestListener, ServletRequestAttributeListener,
        HttpSessionListener, HttpSessionAttributeListener,
        HttpSessionBindingListener, HttpSessionActivationListener {

    /* *******************************************
     *         ServletContextListener
     * *******************************************/

    @Override
    public void contextInitialized(ServletContextEvent sce) {
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }

    /* *******************************************
     *       ServletContextAttributeListener
     * *******************************************/

    @Override
    public void attributeAdded(ServletContextAttributeEvent scab) {
        System.err.println("servletContext add attr: " + scab.getName() + "=" + scab.getValue());
    }

    @Override
    public void attributeRemoved(ServletContextAttributeEvent scab) {
        System.err.println("servletContext remove attr: " + scab.getName());
    }

    @Override
    public void attributeReplaced(ServletContextAttributeEvent scab) {
        System.err.println("servletContext replace attr: " + scab.getName() + "=" + scab.getValue());
    }

    /* *******************************************
     *         ServletRequestListener
     * *******************************************/

    @Override
    public void requestInitialized(ServletRequestEvent sre) {
        System.err.println("request initialized: " + sre.getServletRequest());
    }

    @Override
    public void requestDestroyed(ServletRequestEvent sre) {
        System.err.println("request destoryed: " + sre.getServletRequest());
    }

    /* *******************************************
     *       ServletRequestAttributeListener
     * *******************************************/

    @Override
    public void attributeAdded(ServletRequestAttributeEvent srae) {
        System.err.println("request add attr: " + srae.getName() + "=" + srae.getValue());
    }

    @Override
    public void attributeRemoved(ServletRequestAttributeEvent srae) {
        System.err.println("request remove attr: " + srae.getName() + "=" + srae.getValue());
    }

    @Override
    public void attributeReplaced(ServletRequestAttributeEvent srae) {
        System.err.println("request replace attr: " + srae.getName() + "=" + srae.getValue());
    }

    /* *******************************************
     *           HttpSessionListener
     * *******************************************/

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        System.err.println("session created: " + se.getSession());
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        System.err.println("session destroyed: " + se.getSession());
    }

    /* *******************************************
     *        HttpSessionAttributeListener
     * *******************************************/

    @Override
    public void attributeAdded(HttpSessionBindingEvent se) {
        System.err.println("session add attr: " + se.getName() + "=" + se.getValue());
    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent se) {
        System.err.println("session remove attr: " + se.getName() + "=" + se.getValue());
    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent se) {
        System.err.println("session replace attr: " + se.getName() + "=" + se.getValue());
    }

    /* *******************************************
     *        HttpSessionBindingListener
     * *******************************************/

    @Override
    public void valueBound(HttpSessionBindingEvent event) {
        System.err.println("session value bound: " + event.getName() + "=" + event.getValue());
    }

    @Override
    public void valueUnbound(HttpSessionBindingEvent event) {
        System.err.println("session value unbound: " + event.getName() + "=" + event.getValue());
    }

    /* *******************************************
     *        HttpSessionActivationListener
     * *******************************************/

    // HttpSession 必须跨越转移到其他服务器之前
    @Override
    public void sessionWillPassivate(HttpSessionEvent se) {
    }

    // HttpSession 必须跨越转移到其他服务器之后
    @Override
    public void sessionDidActivate(HttpSessionEvent se) {
    }
}
